package com.wentao.thisService.util;

import com.wentao.thisFacade.domain.result.PartnerAddressInfoResult;
import com.wentao.thisService.model.PartnerAddressInfoEntity;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 工具方法
 * @Author: ZhaiYanTao
 * @Date: 2020/3/5 14:40
 */
public class MyUtils {
    public static void main(String[] args) {
        getSetters(new PartnerAddressInfoEntity(), new PartnerAddressInfoResult());
    }

    private static void getSetters(Object source, Object target) {
        Field[] sourceFields = source.getClass().getDeclaredFields();
        Field[] targetFields = target.getClass().getDeclaredFields();
        if (null != sourceFields && null != targetFields) {
            int printLines = 0;
            List<String> sourceFieldsNameList = new ArrayList<>();
            for (Field sourceField : sourceFields) {
                sourceFieldsNameList.add(sourceField.getName());
            }
            for (Field targetField : targetFields) {
                String targetFieldName = targetField.getName();
                if (sourceFieldsNameList.contains(targetFieldName)) {
                    StringBuilder printString = new StringBuilder();
                    printString.append("target.set");
                    String firstCharUPCase = targetFieldName.substring(0, 1).toUpperCase();
                    printString.append(firstCharUPCase).append(targetFieldName.substring(1));
                    printString.append("(source.get").append(firstCharUPCase).append(targetFieldName.substring(1)).append("());");
                    System.out.println(printString);
                    printLines++;
                } else {
                    System.out.println(String.format("%s : %s", "// 没有属性", targetField.getName()));
                    StringBuilder printString = new StringBuilder();
                    printString.append("target.set");
                    String firstCharUPCase = targetFieldName.substring(0, 1).toUpperCase();
                    printString.append(firstCharUPCase).append(targetFieldName.substring(1));
                    printString.append("();");
                    System.out.println(printString);
                }
            }
            System.out.println(String.format("// target有 %s 个属性，打印了 %s 个方法", targetFields.length, printLines));
        }
    }
}
